<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>待办列表</title>

    <!-- BOOTSTRAP STYLES-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet"/>
    <!-- FONTAWESOME STYLES-->
    <link href="../assets/css/font-awesome.css" rel="stylesheet"/>
    <!--CUSTOM BASIC STYLES-->
    <link href="../assets/css/basic.css" rel="stylesheet"/>
    <!--CUSTOM MAIN STYLES-->
    <link href="../assets/css/custom.css" rel="stylesheet"/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="wrapper">
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12">
                <h6 class="page-subhead-line">系统管理 >> 用户管理</h6>
            </div>
        </div>


        <div class="row">
            <div class="col-md-12">
                <!--   Kitchen Sink -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        *****
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>用户账号</th>
                                    <th>用户名称</th>
                                    <th>角色</th>
                                    <th>邮箱</th>
                                    <th>最后登录时间</th>
                                    <th>状态（启用/未启用）</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="userlist"></tbody>
                            </table>
                            <ul class="pagination">
                                <li>
                                    <a href="">首页</a>
                                </li>
                                <li>
                                    <a href="">&laquo;</a>
                                </li>
                                <li>
                                    <a></a>
                                </li>
                                <li>
                                    <a href="">&raquo;</a>
                                </li>
                                <li>
                                    <a href="">末页</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- End  Kitchen Sink -->
            </div>

        </div>

    </div>

</div>


<!-- /. FOOTER  -->
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
<!-- JQUERY SCRIPTS -->
<script src="../assets/js/jquery-1.10.2.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="../assets/js/bootstrap.js"></script>

<script type="application/javascript">

    $(function () {
        getPage(1);
    })

    function getPage(pageNo) {
        $("#userlist").html("");
        $.ajax({
                url: "http://localhost:8080/user/allUser",
                type: "get",
                data: {"currentPage": pageNo},
                dataType: "json",
                success: function (data) {
                    console.log(data)
                    if (data.status == 200 && data.obj.lists != null) {
                        var pageNum = data.obj.currPage;//当前页数
                        var totalPages = data.obj.totalPage;//总页数
                        var list = data.obj.lists;//每页的显示的数据
                        for (var i = 0; i < list.length; i++) {

                            var userCode = list[i].userCode;
                            var userName = list[i].userName;
                            var roleName = list[i].role.roleName;
                            var email = list[i].email;
                            var lastLoginTime = list[i].lastUpdateTime;
                            var userStatus = list[i].userStatus;
                            var activion;
                            if (userStatus == 1) {
                                userStatus="正常";
                                activion="冻结";
                            }else {
                                userStatus="冻结";
                                activion="正常";
                            }
                            var tr = "<tr>" +
                                "<td>" + userCode + "</td>" +
                                "<td>" + userName + "</td>" +
                                "<td>" + roleName + "</td>" +
                                "<td>" + email + "</td>" +
                                "<td>" + lastLoginTime + "</td>" +
                                "<td>" + userStatus + "</td>" +
                                "<td><a class='btn btn-success' href='javascript: update(" + userName + ")'>"+activion+"</a>&nbsp;&nbsp;" +
                                "<a class='btn btn-success' href='javascript:update(" + userName + ")'>修改</a>&nbsp;&nbsp;" +
                                "<a class='btn btn-success' href='javascript:deluser(" + userName + ")'>删除</a>&nbsp;&nbsp;" +
                                "<a class='btn btn-success' href='javascript:userPage(" + userName + ")'>LOG日志</a></td>" +
                                "</tr>";
                            $("#userlist").append(tr);
                        }

                        /* 按钮换页 */
                        $(".pagination li:eq(0) a").attr("href", "javascript:getPage(1)");
                        $(".pagination li:eq(1) a").attr("href", "javascript:getPage(" + (pageNum - 1) + ")");
                        $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + (pageNum + 1) + ")");
                        $(".pagination li:eq(4) a").attr("href", "javascript:getPage(" + totalPages + ")");

                        if (pageNum <= 1) {
                            $(".pagination li:eq(1) a").attr("href", "javascript:getPage(1)");

                        } else if (pageNum >= totalPages) {
                            $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + totalPages + ")");
                        }
                        //当前页和总页数的显示

                        $(".pagination li:eq(2) a").html(pageNum + "/" + totalPages + "页");

                    } else if (data.status == 500 && data.msg) {
                        alert(data.msg);
                    }
                },
                error: function () {
                    console.log("与后台断开连接！！！");
                }
            }
        )
    }

    function update(userName) {
        alert("进入update");
    }

    deluser
</script>


</body>
</html>
